import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
import './assets/global.css'
import './assets/fonts/iconfont.css'
import ZkTable from 'vue-table-with-tree-grid'
import VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
// 导入axios
import axios from 'axios'
Vue.use(VueQuillEditor)
Vue.component('tree-table', ZkTable)
// 配置请求的baseURL
axios.defaults.baseURL = 'http://liufusong.top:8888/api/private/v1/'
// 请求拦截器
axios.interceptors.request.use(config => {
  // console.log(config)
  if (config.url !== 'login') {
    config.headers.authorization = sessionStorage.getItem('token')
  }
  return config
})

// 将axios挂在到Vue的原型对象上 让全局组件都能使用$axios
Vue.prototype.$axios = axios

// 配置时间过滤器
Vue.filter('dateFormat', dt => {
  // 注意时间对象接受毫秒数  这里dt是秒数 需要乘以1000
  const date = new Date(dt * 1000)
  const Y = date.getFullYear()
  const M = (date.getMonth() + 1).toString().padStart(2, '0')
  const D = date.getDate().toString().padStart(2, '0')
  const h = date.getHours().toString().padStart(2, '0')
  const m = date.getMinutes().toString().padStart(2, '0')
  return `${Y}-${M}-${D} ${h}:${m}`
})

Vue.config.productionTip = false

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
